/*console.h*/

#ifndef __CONSOLE_H__
#define __CONSOLE_H__

#include <ivaria/conin.h>
#include <ivaria/conout.h>
#include <ivaria/script.h>
#include <csutil/scf_implementation.h>
#include <csutil/refcount.h>
#include <iutil/plugin.h>
#include <crystalspace.h>

class ctaConsole:public csRefCount
{
private:

	iObjectRegistry* object_reg;

	struct ExecCallback : public scfImplementation1<ExecCallback,iConsoleExecCallback>
  {
    ExecCallback () : scfImplementationType (this) { }
    virtual ~ExecCallback () { }
    virtual void Execute (const char* cmd);
	csRef<iScript> python;
	bool InitPython(iObjectRegistry *obj_reg);
  };

	bool visible;

	csEventID FinalProcess;

public:
	csRef<iConsoleInput> conin;
	csRef<iConsoleOutput> conout;

	~ctaConsole();

	bool Initialize(iObjectRegistry* obj_reg);

	void Show();

	void Hide();

	void Toggle();

	bool HandleEvent (iEvent& ev);

	bool IsVisible();

	struct EventHandler : public scfImplementation1 <EventHandler, iEventHandler>
	{
		ctaConsole* parent;
		EventHandler (ctaConsole* parent) : scfImplementationType(this),
			parent (parent) {}
		virtual ~EventHandler() {}
		virtual bool HandleEvent (iEvent& e) { return parent->HandleEvent(e); }

		CS_EVENTHANDLER_NAMES("cta.console")
		CS_EVENTHANDLER_NIL_CONSTRAINTS
	};
	csRef<EventHandler> eventHandler;
};
#endif // __CONSOLE_H__
